//
//  BaseRequestVC.m
//  Application
//
//  Created by 薛小刚 on 2018/8/7.
//  Copyright © 2018年 薛小刚. All rights reserved.
//

#import "BaseRequestVC.h"

@interface BaseRequestVC ()

@property (nonatomic, copy) NSString * interface;

@property (nonatomic, strong) NSDictionary * param;

@end

@implementation BaseRequestVC

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.tableview.emptyDataSetSource = self;
//    self.tableview.emptyDataSetDelegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSString *)interface {
    if (self.delegate && [self.delegate respondsToSelector:@selector(requestInterface)]) {
        return [self.delegate requestInterface];
    } else {
        HXLog(@"请实现requestInterface方法");
        return nil;
    }
}

- (NSDictionary *)param {
    if (self.delegate && [self.delegate respondsToSelector:@selector(requestParam)]) {
        return [self.delegate requestParam];
    } else {
        HXLog(@"请实现requestInterface方法");
        return nil;
    }
}

- (void)getData:(BOOL)refresh {
    if (self.interface == nil) {
        return;
    }
    [NetworkingManager getNetworkRequestWithUrlString:self.interface parameters:self.param isCache:refresh succeed:^(id data) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(requestResult:)]) {
            [self.delegate requestResult:data];
        }
    } fail:^(NSError *error) {
        
    }];
}

- (void)postData:(BOOL)refresh {
    if (self.interface == nil) {
        return;
    }
    [NetworkingManager postNetworkRequestWithUrlString:self.interface parameters:self.param isCache:refresh succeed:^(id data) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(requestResult:)]) {
            [self.delegate requestResult:data];
        }
    } fail:^(NSError *error) {
        
    }];
}


//空白页图片
//- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
//    NSString *imageSring = @"page_failed.jpg";
////    NSAssert(imageSring == nil, @"请设置默认图片");
//    UIImage *imageTemp  = IMAGE(imageSring);
//    return imageTemp;
//}


- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    
    return @"数据为空!";
}

- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
    [self getData:YES];
}

@end
